<template>
  <div class="talk">
    <button @click="getLoveTalk">获取一句土味情话</button>
    <ul>
      <li v-for="talk in talkStore.talkList" :key="talk.id">
        {{ talk.title }}
      </li>
    </ul>
  </div>
</template>

<script setup lang="ts" name="LoveTalk">
  import { reactive } from "vue";
  import axios from "axios";
  import { nanoid } from "nanoid"; //随机id
  import { useTalkStore } from "@/store/loveTalk";

  const talkStore = useTalkStore();

  //方法
  async function getLoveTalk() {
    // //发送请求
    // let {
    //   //下面这行的写法是:连续解构加重命名为title
    //   data: { content: title }, //这行的写法是:连续解构加重命名为title
    // } = await axios.get("https://api.uomg.com/api/rand.qinghua?format=json");
    // //把请求回来的字符串，转成一个对象对象
    // let obj = { id: nanoid(), title }; //两种写法都可以 let obj = { id: nanoid(), title: title };
    // //将对象(obj)放入数组(talkList)中
    // talkList.unshift(obj);
  }
</script>

<style scoped>
  .talk {
    background-color: rgb(151, 207, 148);
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
  }
</style>
